//
//  YCTabBar.swift
//  swift微博
//
//  Created by 姚伟聪 on 15/12/15.
//  Copyright © 2015年 姚伟聪. All rights reserved.
//

import UIKit

class YCTabBar: UITabBar {
    
    var count = 5
    
   lazy var comitBtn: UIButton = {
    
    let btn = UIButton()
    btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
    btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
    btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
    btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
    
     self.addSubview(btn)
    
    return btn
    
    }()
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
        var index: CGFloat = 0
        
        let itemWidth = bounds.width / CGFloat(count)
        let itemHeight = bounds.height
        
        
        for item in subviews {
        
            if item is UIControl
            {
                
                item.frame = CGRect(x: itemWidth * index, y: 0, width: itemWidth, height: itemHeight)
//                
//                item.frame = CGRectOffset(frame, itemWidth * index, 0)
                
                index += index == 1 ? 2 : 1
                
            }
        
        }
       
        comitBtn.frame = CGRect(x: 2 * itemWidth, y: 0, width: itemWidth, height: itemHeight)
    
        
        
     
    }
    
    

}
